package com.prodog.gamemodule.gameworld.map.handler;

import com.prodog.command.annonations.Command;
import com.prodog.command.annonations.CommandBean;
import com.prodog.command.annonations.Interceptors;
import com.prodog.command.annonations.Iptor;
import com.prodog.command.entity.CommandResult;
import com.prodog.command.entity.RoleGameCommand;
import com.prodog.gamemodule.gameworld.map.service.GameMapService;
import com.prodog.usermodule.role.interceptor.StateInterceptor;
import com.prodog.usermodule.user.interceptor.NotRegistInterceptor;
import lombok.RequiredArgsConstructor;

@CommandBean(setName = "地图操作")
@RequiredArgsConstructor
@Interceptors(iptors = {
        @Iptor(value = NotRegistInterceptor.class),
        @Iptor(value = StateInterceptor.class, params = "{'requiredStates':[1]}", msg = "[{{state}}]状态下无法进行此操作。")
})
public class GameMapHandler {
    private final GameMapService mapService;

    @Command(value = "([上下左右])", props = "direction")
    public CommandResult move(RoleGameCommand command, String direction) {
        try {
            return mapService.move(command, direction);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器发生错误，移动失败");
        }
    }

    @Command(value = "位置")
    public CommandResult currentMap(RoleGameCommand command) {
        try {
            return mapService.currentMap(command);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器发生错误，获取失败");
        }
    }
}
